package com.wyx.Config;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
//Redis序列化配置 key的序列化
// 假如value存的是一个对象的话 尽量使用Redistemplate
//假如value存的是一个String的话 尽量使用StringRedistemplate 性能好
@Configuration
public class redisConfig extends CachingConfigurerSupport {
    @Bean
    public RedisTemplate<Object,Object>redisTemplate(RedisConnectionFactory factory){
            RedisTemplate<Object,Object>redisTemplate=new RedisTemplate<>();
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
            redisTemplate.setConnectionFactory(factory);
            return redisTemplate;
    }

}
